﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Weazel.Willows.PreliminaryModel
{
	public class TypedItem
		: PreliminaryItemBase
	{		
		public Weazel.Willows.Model.TypeRegistry TypeRegistry
		{
			get { return Model.TypeRegistry; }		
		}

		private Weazel.Willows.Model.Type type;
		public Weazel.Willows.Model.Type Type
		{
			get { return type; }
			protected set { type = value; }
		} 

		public TypedItem(Model model)
			: base(model)
		{		
		}

		public void ReadType(XmlElement element)
		{
			if (element.HasAttribute("width"))
			{
				Weazel.Willows.Model.BasicType subType = 
					TypeRegistry[element.Attributes["type"].Value];

				int width = int.Parse(element.Attributes["width"].Value);
				type = new Weazel.Willows.Model.Type(TypeRegistry, subType, width);
			}
			else
			{
				type = TypeRegistry[element.Attributes["type"].Value] as 
					Weazel.Willows.Model.Type;
			}
		}
	}
}
